package game.servlet;

import game.remoteService.RemoteServiceFactory;
import game.remoteService.interfaces.RemoteService;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * Game's service servlet.
 * 
 * @author Linzy
 * Create Date: 2009 9 4 10:39:55
 * 
 */
public class GameService extends HttpServlet {

	private static final long serialVersionUID = 6795309755270489593L;

	// xml file header
	private String xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; 

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
//		String service = request.getParameter(SysStatic.getInstance().servNameParam);
		String service = "";
		
		StringBuffer contents = new StringBuffer();
		contents.append(xmlHeader);
		
		try {
			RemoteService instance = RemoteServiceFactory.buildService(service);
			if(instance == null){
				contents.append("<result>false</result>");
			}else{
				instance.doService(request, contents);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		PrintWriter out = response.getWriter();
		out.println(contents.toString());
		out.close();
	} // doGet()

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
	
	
	
} // end of class
